package com.js.auth.server.module.client.controller;

import com.js.auth.server.module.client.entity.AuthClient;
import com.js.auth.server.module.client.service.AuthClientService;
import com.js.common.controller.BaseController;
import com.js.common.response.ObjectRestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ygl
 * @create 2018-11-06
 * @DESCRIPTION
 **/
@RestController
@RequestMapping("service")
public class ServiceController extends BaseController<AuthClient,String> {

    @Autowired
    private AuthClientService authClientService;

    @PutMapping("/{id}/client")
    public ObjectRestResponse modifyUsers(@PathVariable String id, String clients){
        authClientService.modifyClientServices(id, clients);
        return new ObjectRestResponse();
    }

    @RequestMapping(value = "/{id}/client", method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse<List<AuthClient>> getUsers(@PathVariable String id){
        ObjectRestResponse<List<AuthClient> > entityObjectRestResponse = new ObjectRestResponse<>();
        Object o = authClientService.getClientServices(id);
        entityObjectRestResponse.data((List<AuthClient>)o);
        return entityObjectRestResponse;
    }
}
